
<template>
  <div class="wrap" style="padding: 15px">
    <el-row>
      <el-form :inline="true" :model="formData" class="demo-form-inline">
        <el-form-item label="项目名称">
          <el-input
            v-model="queryParams.name"
            clearable
            placeholder="请输入项目名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="项目状态">
          <el-select
            v-model="queryParams.status"
            clearable
            placeholder="请选择"
          >
            <el-option label="开启" value="1"> </el-option>
            <el-option label="关闭" value="0"> </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="getData">查询</el-button>
        </el-form-item>
      </el-form>
    </el-row>
    <el-row>
      <el-button type="primary" style="margin-bottom: 15px" @click="add"
        >新增</el-button
      >
    </el-row>

    <el-table :data="tableData" style="width: 100%" stripe v-loading="loading">
      <el-table-column type="index" label="序号"></el-table-column>
      <el-table-column label="项目名称" prop="name"></el-table-column>
      <el-table-column label="项目状态">
        <template slot-scope="scope">
          {{ scope.row.status == 0 ? "关闭" : "开启" }}
        </template>
      </el-table-column>
      <!-- <el-table-column label="项目图片">
        <template slot-scope="scope">
          <el-image
            style="width: 100px; height: 100px"
            :src="scope.row.picUrl"
          ></el-image>
        </template>
      </el-table-column> -->
      <el-table-column label="同行人数" prop="personCount"></el-table-column>
      <el-table-column label="创建时间" prop="createTime"></el-table-column>

      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="primary" size="small" @click="edit(scope.row)"
            >编辑</el-button
          >

          <el-button type="danger" size="small" @click="del(scope.row.id)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <div class="block" style="text-align: right">
      <el-pagination
        @size-change="getData"
        @current-change="getData"
        :current-page.sync="queryParams.page"
        :page-sizes="[10, 20, 30, 40]"
        :page-size.sync="queryParams.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>
    <Add ref="add" />
  </div>
</template>
<script>
import { itemPageList, itemDel } from '@/config/api'
import Add from './add.vue'

export default {
  components: {
    Add
  },
  data () {
    return {
      formData: {
        user: undefined,
        id: undefined,
        state: undefined,
        page: 1,
        pageSize: 10,
      },
      queryParams: {
        page: 1,
        pageSize: 10,
        name: "",
        status: ""
      },

      tableData: [],
      total: 0,
      loading: false,

    };
  },

  created () {
    this.getData()
  },
  methods: {
    // 新增
    add () {
      this.$refs.add.addShow()
    },
    edit (recore) {
      this.$refs.add.editShow(recore)
    },
    getData () {
      itemPageList(this.queryParams).then(res => {
        this.tableData = res.data.result.list
        this.regulationName = ""
        this.total = res.data.result.total
      })
    },
    del (id) {
      this.$confirm('此操作将删除该方案, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        itemDel({ id }).then(res => {
          if (res.data.status == 200) {
            this.getData()
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
          }

        })

      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },

  },
};
</script>
